/**
 * Copyright (C) 2013-2014 the original author or authors.
 */
package com.foreveross.bsl.comments.application.impl;

import java.io.IOException;
import java.util.Properties;

import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Component;

/**
 * xxx
 * 
 * @author Wangyi
 * @version v1.0
 * 
 * @date 2013-9-25
 * 
 */
@Component
public class NoticeConfig implements ResourceLoaderAware {
	public static final String DEFAULT_ROLE_KEY_NAME = "privileges";
	
	private String roleKeyName=DEFAULT_ROLE_KEY_NAME;
	
	public NoticeConfig(){
	}
	
	@Override
	public void setResourceLoader(ResourceLoader resourceLoader) {
		final String path="classpath:/application.properties";
		Resource res=resourceLoader.getResource(path);
		if(res.exists()){
			try {
				Properties props=new Properties();
				props.load(res.getInputStream());
				this.setRoleKeyName(props.getProperty("notice.rolekeyname", DEFAULT_ROLE_KEY_NAME));
			} catch (IOException e) {
				//ignore
			}
		}
	}

	/**
	 * @return the roleKeyName
	 */
	public String getRoleKeyName() {
		return roleKeyName;
	}

	/**
	 * @param roleKeyName
	 *            the roleKeyName to set
	 */
	public void setRoleKeyName(String roleKeyName) {
		this.roleKeyName = roleKeyName;
	}

}
